# $OpenBSD: Makefile,v 1.43 2017/05/31 08:08:17 espie Exp $

# XXXTODO: Subpackage facter.jar for use with puppetserver
COMMENT =		collect and display system facts

VERSION =		3.6.4
DISTNAME =		facter-${VERSION}
SHARED_LIBS +=  	facter                    3.1 # 3.2
PKGSPEC =		facter->=3.0,<4.0
CATEGORIES =		sysutils
REVISION =		0

MAINTAINER =		Sebastian Reitenbach <sebastia@openbsd.org>

# Apache2
PERMIT_PACKAGE_CDROM =	Yes

MASTER_SITES =		https://downloads.puppetlabs.com/facter/

MODULES +=		devel/cmake \
			lang/ruby

COMPILER =		gcc

WANTLIB += boost_atomic-mt boost_chrono-mt boost_date_time-mt
WANTLIB += boost_filesystem-mt boost_locale-mt
WANTLIB += boost_program_options-mt boost_regex-mt boost_system-mt
WANTLIB += boost_thread-mt c crypto curl m pthread yaml-cpp
WANTLIB += ${LIBECXX} cpp-hocon
WANTLIB += leatherman_curl leatherman_dynamic_library
WANTLIB += leatherman_execution leatherman_file_util leatherman_locale
WANTLIB += leatherman_logging leatherman_ruby leatherman_util

LIB_DEPENDS =		devel/boost>=1.58 \
			devel/cpp-hocon \
			devel/leatherman>=0.12.1p1 \
			devel/yaml-cpp \
			net/curl

BUILD_DEPENDS =		devel/gettext-tools

CONFIGURE_ARGS+=	-DFACTER_RUBY="${LOCALBASE}/lib/libruby${MODRUBY_BINREV}.so" \
			-DRUBY_LIB_INSTALL="${PREFIX}/lib/ruby/vendor_ruby/${MODRUBY_REV}" \
			-DWITHOUT_JRUBY:Bool=Yes

# NB:
# When/if SERVER-14 is resolved, drop the `-DWITHOUT_JRUBY:Bool=Yes`
# then use a pre-build target to run the ninja `facter-jruby` target
# to generate the JNI header file.

LIBfacter_MAJOR =	${LIBfacter_VERSION:R}
LIBfacter_MINOR =	${LIBfacter_VERSION:E}
SUBST_VARS +=		MODRUBY_BINREV MODRUBY_REV LIBfacter_MAJOR LIBfacter_MINOR

CXXFLAGS +=		-pthread

post-extract:
	rm -f ${WRKDIST}/cmake/FindRuby.cmake

pre-configure:
	${SUBST_CMD} ${WRKSRC}/CMakeLists.txt ${WRKSRC}/lib/CMakeLists.txt \
		${WRKSRC}/lib/src/facts/posix/cache.cc

# Install symlinked libfacter.so so Ruby can load libfacter.so as it refuses
# to load with the version appended.
post-install:
	ln -s ./libfacter.so.${LIBfacter_VERSION} ${PREFIX}/lib/libfacter.so
	mv ${PREFIX}/bin/facter-${VERSION} ${PREFIX}/bin/facter

.include <bsd.port.mk>
